﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Equin.ApplicationFramework;

namespace MoneyWentWhere.WinFormsUI.UI.DataGrid
{
    class DataGridViewX : DataGridView
    {
        public int DataEntryRowIndex
        {
            get
            {
                IBindingListViewWithInsert view = BindingListViewWithInsert;
                if (view == null) { return -1; }

                switch (view.InsertMode)
                {
                    case RowInsertMode.Top: return 0;
                    case RowInsertMode.Bottom: return Rows.Count - 1;
                    default: return -1;
                }
            }
        }

        IBindingListViewWithInsert BindingListViewWithInsert
        {
            get
            {
                IBindingListViewWithInsert wi = DataSource as IBindingListViewWithInsert;
                if (wi != null) { return wi; }

                BindingSource bs = DataSource as BindingSource;
                if (bs != null) 
                { 
                    wi = bs.DataSource as IBindingListViewWithInsert;
                    if (wi != null) { return wi; }
                }

                return null;
            }

        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            Trace.Write((int)keyData+" ");
            return base.ProcessDialogKey(keyData);
        }

        protected override bool ProcessDataGridViewKey(KeyEventArgs e)
        {
            Trace.Write((int)e.KeyData + "/");
            return base.ProcessDataGridViewKey(e);
        }
    }
}
